package scau.mis4.chanyulin.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import scau.mis4.chanyulin.dao.IGoodMapper;
import scau.mis4.chanyulin.entity.GoodDetail;
import scau.mis4.chanyulin.service.IGoodDetailService;
import scau.mis4.chanyulin.entity.Good;
import scau.mis4.chanyulin.service.IGoodService;
import java.util.List;

/**
 * Created by cyl on 2018/03/27.
 * Good Service实现
 */
@Service
public class GoodServiceImpl extends AbstractBaseService<Good> implements IGoodService {

    @Autowired
    private IGoodMapper goodMapper;
    @Autowired
    private IGoodDetailService goodDetailService;

    public List<Good> findAll() {
        return goodMapper.findAllGood();
    }

    @Override
    public int deleteGoodAndDetail(String goodId) {
        return goodMapper.deleteGoodAndDetailByGoodId(goodId);
    }

//    public int delete(Object goodId) {
//        List<Good> goodList = findByProperties(goodId.toString(), "id");
//        for (Good g:goodList) {
//            List<GoodDetail> goodDetailList = goodDetailService.findByProperties(g.getId(), "goodId");
//            for (GoodDetail gd : goodDetailList) {
//                goodDetailService.delete(gd.getId());
//            }
//            goodMapper.deleteByPrimaryKey(g.getId());
//        }
//        return 0;
//    }

    @Override
    public Good findByKey(Object goodId) {
        return goodMapper.findGoodById(goodId.toString());
    }

    @Override
    public Good findByGoodNo(String goodNo) {
        return goodMapper.findGoodByGoodNo(goodNo);
    }

}
